<template>
	<layout :loading="loading" curPage="user" :title="data.id ? '修改用户':'新增用户'">

		<form class="layui-form" @submit="submit" data-action="/admin/user/save" data-rediret="/pages/user/userList">

			<div style="width: 650px;">
				
				<multiSelect title="角色" :list="roleList" name="x.roleIds" :value="data.roleIds" titleKey="name" valueKey="id"></multiSelect>
				
				<inputGroup name="x.name|用户名" title="用户名" :value="data.name"></inputGroup>
				
				<inputGroup name="x.password|密码|6~20|empty" title="密码" v-if="!!data.id || data.id == 0" placeholder="不修改请留空"></inputGroup>
				<inputGroup name="x.password|密码|6~20" title="密码" v-else></inputGroup>
				
				<inputGroup name="x.contact|姓名|2~10" title="姓名" :value="data.contact"></inputGroup>
				
				<inputGroup type="number" name="x.mobile|联系电话|mobile" title="联系电话" :value="data.mobile"></inputGroup>
				
				<inputGroup name="x.remark|备注|0~200|empty" title="备注" :value="data.remark"></inputGroup>

			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="x.id" :value="id" style="display: none;">
					<button class="layui-btn" form-type="submit">{{ !data.id ? '保存' : '修改'}}</button>
					<button class="layui-btn layui-btn-primary" form-type="reset">重置</button>
					<button class="layui-btn layui-btn-primary" @click="kit.goBack('index')">取消</button>
				</div>
			</div>
		</form>

	</layout>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				id : '' ,
				data : {
					userType : ""
				},
				roleList : [],
				baseList : [] ,
				baseId : ""
			}
		},
		
		onLoad(params) {
			this.id = params.id ;
			this.loadData();
		},
		
		methods: {
			
			submit:function(e){
				this.form.submit(e);
			},
			
			loadData : function(e){
				var that = this ;
				var data = {
					id : this.id 
				} ;
				this.kit.get("/admin/user/info",data,function(res){
					that.data = res.data || that.data ;	
					var baseList = res.baseList || [] ;
					baseList.unshift({
						id : 0 ,
						name : "全部"
					});
					that.baseList = baseList ;
					that.roleList = res.roleList || [];
					that.baseId = res.baseId ;
				});
			}
		}
	}
</script>

<style>

</style>
